package com.example.weli.ble2test;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.View;

public class Bar6Ch extends View {
    int[] ch_value;
    private Paint mPaint_Ch1;
    private Paint mPaint_Ch2;
    private Paint mPaint_Ch3;
    private Paint mPaint_Ch4;
    private Paint mPaint_Ch5;
    private Paint mPaint_Ch6;
    private Paint mPaint_Lin;
    private Paint mPaint_Text;

    public Bar6Ch(Context context) {
        super(context);
        this.ch_value = new int[6];
        initial_bar();
    }

    public Bar6Ch(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.ch_value = new int[6];
        initial_bar();
    }

    public Bar6Ch(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.ch_value = new int[6];
        initial_bar();
    }

    void initial_bar() {
        this.mPaint_Ch1 = new Paint();
        this.mPaint_Ch2 = new Paint();
        this.mPaint_Ch3 = new Paint();
        this.mPaint_Ch4 = new Paint();
        this.mPaint_Ch5 = new Paint();
        this.mPaint_Ch6 = new Paint();
        this.mPaint_Lin = new Paint();
        this.mPaint_Text = new Paint();
        this.mPaint_Ch1.setStyle(Style.FILL);
        this.mPaint_Ch1.setColor(Color.rgb(190, 206, 161));
        this.mPaint_Ch2.setStyle(Style.FILL);
        this.mPaint_Ch2.setColor(Color.rgb(240, 160, 161));
        this.mPaint_Ch3.setStyle(Style.FILL);
        this.mPaint_Ch3.setColor(Color.rgb(188, 168, 255));
        this.mPaint_Ch4.setStyle(Style.FILL);
        this.mPaint_Ch4.setColor(Color.rgb(156, 193, 182));
        this.mPaint_Ch5.setStyle(Style.FILL);
        this.mPaint_Ch5.setColor(Color.rgb(247, 184, 134));
        this.mPaint_Ch6.setStyle(Style.FILL);
        this.mPaint_Ch6.setColor(Color.rgb(255, 220, 120));
        this.mPaint_Lin.setColor(-1);
        this.mPaint_Text.setColor(-1);
        this.mPaint_Text.setTextSize(10.0f);
        this.mPaint_Text.setFakeBoldText(true);
        for (int i = 0; i < 6; i++) {
            this.ch_value[i] = 60;
        }
    }

    public void setCHvalue(int index, int value) {
        if (value <= 100 && value >= 0) {
            this.ch_value[index - 1] = (value / 2) + 35;
            invalidate();
        }
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawLine(60.0f, 0.0f, 60.0f, 74.0f, this.mPaint_Lin);
        canvas.drawLine(50.0f, 74.0f, 70.0f, 74.0f, this.mPaint_Lin);
        canvas.drawLine(50.0f, 0.0f, 70.0f, 0.0f, this.mPaint_Lin);
        canvas.drawRect(new Rect(60, 2, this.ch_value[0], 12), this.mPaint_Ch1);
        canvas.drawLine(34.0f, (float) 2, 34.0f, (float) 12, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) 2, 86.0f, (float) 12, this.mPaint_Lin);
        int start = 2 + 12;
        if (this.ch_value[0] < 60) {
            canvas.drawText("1", 54.0f, (float) 10, this.mPaint_Text);
        } else {
            canvas.drawText("1", 62.0f, (float) 10, this.mPaint_Text);
        }
        canvas.drawRect(new Rect(60, start, this.ch_value[1], 24), this.mPaint_Ch2);
        canvas.drawLine(34.0f, (float) start, 34.0f, (float) 24, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) start, 86.0f, (float) 24, this.mPaint_Lin);
        start += 12;
        if (this.ch_value[1] < 60) {
            canvas.drawText("2", 54.0f, (float) 22, this.mPaint_Text);
        } else {
            canvas.drawText("2", 62.0f, (float) 22, this.mPaint_Text);
        }
        canvas.drawRect(new Rect(60, start, this.ch_value[2], 36), this.mPaint_Ch3);
        canvas.drawLine(34.0f, (float) start, 34.0f, (float) 36, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) start, 86.0f, (float) 36, this.mPaint_Lin);
        start += 12;
        if (this.ch_value[2] < 60) {
            canvas.drawText("3", 54.0f, (float) 34, this.mPaint_Text);
        } else {
            canvas.drawText("3", 62.0f, (float) 34, this.mPaint_Text);
        }
        canvas.drawRect(new Rect(60, start, this.ch_value[3], 48), this.mPaint_Ch4);
        canvas.drawLine(34.0f, (float) start, 34.0f, (float) 48, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) start, 86.0f, (float) 48, this.mPaint_Lin);
        start += 12;
        if (this.ch_value[3] < 60) {
            canvas.drawText("4", 54.0f, (float) 46, this.mPaint_Text);
        } else {
            canvas.drawText("4", 62.0f, (float) 46, this.mPaint_Text);
        }
        canvas.drawRect(new Rect(60, start, this.ch_value[4], 60), this.mPaint_Ch5);
        canvas.drawLine(34.0f, (float) start, 34.0f, (float) 60, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) start, 86.0f, (float) 60, this.mPaint_Lin);
        start += 12;
        if (this.ch_value[4] < 60) {
            canvas.drawText("5", 54.0f, (float) 58, this.mPaint_Text);
        } else {
            canvas.drawText("5", 62.0f, (float) 58, this.mPaint_Text);
        }
        canvas.drawRect(new Rect(60, start, this.ch_value[5], 72), this.mPaint_Ch6);
        canvas.drawLine(34.0f, (float) start, 34.0f, (float) 72, this.mPaint_Lin);
        canvas.drawLine(86.0f, (float) start, 86.0f, (float) 72, this.mPaint_Lin);
        start += 12;
        if (this.ch_value[5] < 60) {
            canvas.drawText("6", 54.0f, (float) 70, this.mPaint_Text);
        } else {
            canvas.drawText("6", 62.0f, (float) 70, this.mPaint_Text);
        }
    }

    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        setMeasuredDimension(120, 80);
    }
}
